import request from '../tools/request'

//获取用户信息
export function userAPI(data) {
  return request({
    url: '/admin/users',
    method: 'get',
    data
  }).then((res) => res.data)
}

//--------------------------------------------------------------------------------
//获取角色信息
export function roleAPI(data) {
  return request({
    url: '/admin/roles',
    method: 'get',
    data
  }).then((res) => res.data)
}
//新增角色信息
export function AddRole(data) {
  return request({
    url: '/admin/roles',
    method: 'post',
    data
  }).then((res) => res)
}

//删除角色信息
export function deleteRole(id) {
  return request({
    url: `/admin/roles/${id}`,
    method: 'delete'
  }).then((res) => res)
}

//修改角色信息
export function xiuRole(id, data) {
  return request({
    url: `/admin/roles/${id}`,
    method: 'patch',
    data
  }).then((res) => res)
}

//查询单条数据记录
export function chaRoles(id) {
  return request({
    url: `/admin/roles/${id}`,
    method: 'get'
  }).then((res) => res.data)
}

//-------------------------------------------------------------------
//获取权限信息
export function permissionAPI(data) {
  return request({
    url: '/admin/permissions',
    method: 'get',
    data
  }).then((res) => res.data)
}

//新增权限信息
export function addPermission(data) {
  return request({
    url: '/admin/permissions',
    method: 'post',
    data
  }).then((res) => res)
}

//删除权限信息
export function delPermission(id) {
  return request({
    url: `/admin/permissions/${id}`,
    method: 'delete'
  }).then((res) => res)
}

//修改权限信息
export function xiuPermission(id, data) {
  return request({
    url: `/admin/permissions/${id}`,
    method: 'patch',
    data
  }).then((res) => res)
}

//----------------------------------------------------------------------

//获取用户列表
export function managersAPI(name = '', page = 1, per = 10) {
  return request({
    url: `/admin/managers?name=${name}&page=${page}&per=${per}`,
    method: 'get'
  }).then((res) => res.data)
}
